using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SenceController : MonoBehaviour
{

    [Header("Max BackGround Move Pos X")]
    public float moveParameterX;
    public float moveParameterY;

    [Header("Set StartPos")]
    public float startPosX;
    public float startPosY;

    [Header("Set EndPos")]
    public float endPosX;
    public float endPosY;

    private float initSenceX;
    private float initSenceY;

    // Start is called before the first frame update
    void Start()
    {
        initSenceX = transform.position.x;
        initSenceY = transform.position.y;
    }

    private void Update()
    {
        
    }

    // Update is called once per frame
    private void FixedUpdate()
    {

        ActiveObject obj = getMoveTarget();


        if (obj != null && !obj.isDestroyed() && obj.gameObject)
        {
            if (endPosX != startPosX && moveParameterX != 0.0f)
            {
                float posX = obj.gameObject.transform.position.x;
                Vector2 p = transform.position;
                p.x = Com.getUnformVelocity(startPosX, posX, endPosX, initSenceX, initSenceX + moveParameterX);
                transform.position = p;
            }

            if (endPosY != startPosY && moveParameterY != 0.0f)
            {
                float posY = obj.gameObject.transform.position.y;
                Vector2 p = transform.position;
                p.y = Com.getUnformVelocity(startPosY, posY, endPosY, initSenceY, initSenceY + moveParameterY);
                transform.position = p;
            }

        }


    }


    protected ActiveObject getMoveTarget()
    {
        return CameraMoveEvent.getTarget();
    }



}













